<template>

    <!-- 查询请假历史 -->
    
    <el-table
      :data="tableData"
      style="width: 100% ;"
      :default-sort="{ prop: 'time', order: 'descending' }"
    >
      <!-- <el-table-column label="学号" width="150">
        <template v-slot="scope">
          <span @click="change(scope)">{{ scope.row.Student_Id }}</span>
        </template>
      </el-table-column> -->
      <el-table-column prop="id" label="学号" width="100">{{ student_id }}</el-table-column>
      <el-table-column prop="start_date" label="开始时间" width="180"> </el-table-column>
      <el-table-column prop="end_date" label="结束时间" width="180"></el-table-column>
      <el-table-column prop="leave_type" label="请假类型" width="180"></el-table-column>
      <el-table-column prop="reason" label="请假原因" width="180"></el-table-column>
      <el-table-column prop="status" label="当前状态" width="180"></el-table-column>
      <el-table-column prop="created_at" label="申请时间" width="180"></el-table-column>
      <el-table-column label="" ></el-table-column>
    </el-table>
    <!-- <div class="mt-6 flex justify-center">
      <el-pagination
        background
        layout="prev, pager, next"
        :page-size="10"
        :total="max"
        @current-change="page($event)"
      >
      </el-pagination>
    </div> -->
</template>

<script setup>
    import { onMounted, ref } from "vue";
    // import leaveHistory from "@/modules/leave/leave_history";
    import leaveHistory from '@/modules/leave/select-leave';

    let tableData = ref([]);

    let student_id = ref(localStorage.getItem("id"));


    // 页面加载前
    onMounted(()=>{

        init();

    })


    const init = async () => {
        
        let student_id = localStorage.getItem("id");

        let params = {
            student_id : student_id
        }
        
        let res =  await leaveHistory(params);
        console.log(res);

        if ( res.success ){

            res.data.forEach(item => {
                if (item.status === "Pending") {

                    item.status = "待处理";

                } else if (item.status === "Approved") {

                    item.status = "已批准";

                } else if (item.status === "Rejected") {

                    item.status = "已拒绝";
                };
            });
            tableData.value = res.data;

        }


    }


</script>


<style scoped>

</style>